import json
import os
from pathlib import Path

# 获取当前文件的路径
current_file_path = Path(__file__).resolve()
# 获取根项目目录
project_root = current_file_path.parent

city_params_path = os.path.join(project_root, 'city')
docx_template_path = os.path.join(project_root, 'docx')
fixed_params_path = os.path.join(project_root, 'fix')
command_params_path = os.path.join(project_root, 'command')
ai_params_path = os.path.join(project_root, 'ai')
gen_docx_path = os.path.join(project_root, 'gen')


# 将配置文件内容转换成字典
def need_to_dict(file_path, *args):
    params_dict = {}
    # 对城市配置参数进行字典化
    with open(file_path, 'r', encoding='utf-8') as f:
        jsonvalue = json.load(f)
        if 'city' in file_path:
            jsonArray = jsonvalue.get('data')
            # 第一个参数是 city
            city = args[0]
            for item in jsonArray:
                if item.get('city') == city:
                    params_dict = item
                    break
    return params_dict
